package com.useeinfo.oa.open.admin.wuHanCommon;

import com.useeinfo.framework.extend.action.BaseAction;
import com.useeinfo.framework.sugar.data.QueryParam;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.security.util.SessionKeyUtils;
import com.useeinfo.oa.modules.wuHanCommon.base.biz.WarningDetailBiz;
import com.useeinfo.oa.modules.wuHanCommon.base.entity.WarningDetail;
import com.useeinfo.oa.modules.wuHanCommon.base.result.ResultDto_Wh;
import com.useeinfo.oa.modules.wuHanCommon.base.result.ResultUtil_Wh;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/web/wuhan/warningDetail")
public class WarningDetailAction extends BaseAction {

    @Autowired
    private WarningDetailBiz warningDetailBiz;

    /**
     * 分页获取JSON数据
     */
    @RequestMapping("/getWarningDetailListJSON")
    @ResponseBody
    public ResultDto_Wh getWarningDetailListJSON(@RequestParam(value = "pageNo", required = false) String pageNowParam,
                                                 @RequestParam(value = "pageSize", required = false) String pageSizeParam,
                                                 @RequestParam(value = "orderBy", required = false) String orderBy,
                                                 @RequestParam(value = "searchCode", required = false) String searchCode,
                                                 HttpServletRequest request) {
        SystemUser systemUser = SessionKeyUtils.getSessionUser(request);
        QueryParam queryParam = new QueryParam(pageNowParam, pageSizeParam);
        queryParam.getSqlMap().put("searchCode", searchCode);
        queryParam.getSqlMap().put("userId", systemUser == null || systemUser.getId() == null ? "-1" : systemUser.getId() + "");
        if (StringUtils.isNotBlank(orderBy))
            queryParam.setSqlOrder("order by " + orderBy);
        return ResultUtil_Wh.success(warningDetailBiz.findJSONList(queryParam));
    }

    /**
     * 获取详情
     *
     * @return
     */
    @RequestMapping("/getWarningDetailJSON")
    @ResponseBody
    public ResultDto_Wh getWarningDetailJSON(@RequestParam(value = "id", required = false) String warningDetailId) {

        WarningDetail warningDetail = warningDetailBiz.findModel(StringConverters.ToLong(warningDetailId));
        if (warningDetail == null) {
            return ResultUtil_Wh.error("报警不存在");
        }
        return ResultUtil_Wh.success(warningDetail.toJSONObjectView());
    }

}
